<template>
  <div>
    <!-- 轮播图 -->
    <van-swipe :autoplay="3000">
      <van-swipe-item v-for="(image, index) in images" :key="index">
        <img
          style="height: 212px"
          v-lazy="'http://liufusong.top:8080' + image.imgSrc"
        />
      </van-swipe-item>
    </van-swipe>
    <!-- 搜索框 -->
    <van-search show-action v-model="value" placeholder="请输入搜索关键词">
      <template #label>
        <span>上海</span>
        <van-icon @click="CityList" name="arrow-down" />
      </template>
      <template #action>
        <van-icon name="location-o" />
      </template>
    </van-search>

    <van-grid icon-size="40px">
      <van-grid-item icon="wap-home-o" text="整租" />
      <van-grid-item icon="friends-o" text="合租" />
      <van-grid-item icon="location-o" text="地图找房" />
      <van-grid-item icon="wap-home-o" text="去出租" />
    </van-grid>

    <div class="rent">
      <div class="title">
        <h3>租房小组</h3>
        <span class="more">更多</span>
      </div>
      <van-grid icon-size=50px gutter=10px direction="horizontal" :column-num="2">
        <van-grid-item
          v-for="item in rent"
          :key="item.id"
          :icon="'http://liufusong.top:8080'+ item.imgSrc"
          :text="item.title + item.desc"
        />
      </van-grid>
    </div>
  </div>
</template>

<script>
import { getPicList, getRent } from '@/api/Home.js'
export default {
  data () {
    return {
      images: [],
      value: '',
      rent: []
    }
  },

  created () {
    this.getPicList()
    this.getRent()
  },

  methods: {
    async getPicList () {
      try {
        const res = await getPicList()
        this.images = res.data.body
      } catch (err) {
        console.log(err)
      }
    },
    CityList () {
      this.$router.push('/citylist')
    },
    async getRent () {
      try {
        const res = await getRent()
        this.rent = res.data.body
      } catch (err) {
        console.log(err)
      }
    }
  }
}
</script>

<style scoped lang="less">
div {
  position: relative;

  .van-search {
    position: absolute;
    top: 25px;
    left: 20px;
    width: 350px;
    padding: 0 10px;
    background-color: transparent;
    .van-search__content {
      padding: 0;
    }

    /deep/ .van-icon-arrow-down {
      font-size: 12px;
    }
  }
  .rent {
    padding: 0 10px;
    background-color: #f6f5f6;

    .title {
      display: flex;
      justify-content: space-between;
      height: 47px;
      line-height: 47px;

      h3 {
        font-size: 15px;
        margin: 0;
      }
      .more {
        font-size: 14px;
        color: #787d82;
      }
    }
  }
}
</style>
